﻿#include"test.h"
#include"XQHttpClient.h"
#include"XQHttpHeadReply.h"
#include"XQHttpHeadRequest.h"
#include<QApplication>
#include<QJsonObject>
#include<QFile>
#include<QDebug>

void httpClient()
{
    auto Client = new XQHttpClient(NetworkType::Tcp);
    QObject::connect(qApp, &QApplication::aboutToQuit, Client, &QObject::deleteLater);//设置内存释放

    using Debug = Http::Debug;
    XQHttpClient& http=*Client;
    http.setDebugModels(Debug::Run | Debug::Connection | Debug::Disconnect | Debug::error);

    auto request = http.request();
    request->setHeader("Model","PushMessage");
    request->setHeader("Command", "Account");
    request->setHeader("Type", "Login");

    //http.connectToServerWait("http://192.168.1.3/ftp/notebook/find.exe");
    //http.get();

    http.setUrl("https://www.727370630.top:6666/12313/4545");
    http.connectToServerWait();
    QJsonObject object;
    object.insert("account","1212");
    object.insert("password", "654656");
    http.post(QJsonDocument(object).toJson());

    //http.sendSignals("test", { 1,2,"你好" });
    //http.sendSignals("test", { 1,2,"你好" });
    /*  http.addSlotFunc("server", [&](const QVariantList& list)->QVariantList
          {
              qDebug() << "服务器群发" << list;
              return { };
          });*/
          //QObject::connect(&http, &XQHttpClient::headReplyRead, [](const XQHttpHeadReply& head) {
          //    qDebug() << "服务器响应数据" << head.content_toString();
          //    });
    QObject::connect(&http, &XQHttpClient::signalsRequest, [](const QString& name, const QVariantList& data) {
        qDebug() << "signals 服务器" << name << data;
        });

    /* QString text=XQHttpClient::Post_Reply(NetworkType::Local,"http://127.0.0.1:6666/12313/4545", QByteArray("你好吗"));
     qDebug() << text;*/
     //XQHttpClient::Post(NetworkType::Local, "http://127.0.0.1:6666/12313/4545", QByteArray("我在的"));
}